<template>
  <div style="height: 100vh; display: flex; align-items: center; justify-content: center; background-color: #0f9876">
    <div style="display: flex; background-color: white; width: 50%; border-radius: 5px; overflow: hidden">
      <div style="flex: 1">
        <img src="@/assets/login.png" alt="" style="width: 100%">
      </div>
      <div style="flex: 1; display: flex; align-items: center; justify-content: center">
        <el-form :model="user" style="width: 80%" :rules="rules">
          <div style="font-size: 20px; font-weight: bold; text-align: center; margin-bottom: 20px">欢迎登录阿达西后台管理系统</div>
          <el-form-item prop="username">
            <el-input prefix-icon="el-icon-user" size="medium" placeholder="请输入账号" v-model="user.username"></el-input>
          </el-form-item>
          <el-form-item prop="password">
            <el-input prefix-icon="el-icon-lock" size="medium" placeholder="请输入密码" v-model="user.password"></el-input>
          </el-form-item>

          <el-form-item>
            <el-button type="primary" style="width: 100%" @click="login">登 录</el-button>
          </el-form-item>
          <div style="display: flex">
            <div style="flex: 1">还没有账号？请 <span style="color: #0f9876; cursor: pointer"
                @click="$router.push('/register')">注册</span></div>
          </div>
        </el-form>
      </div>
    </div>

  </div>
</template>



<script >
import { ref } from 'vue';
import request from "@/utils/request";
import router from "../router";



export default {

  setup() {
    const user = ref({
      username: "",
      password: "",

    });


    const login = () => {

      request.post("/manager/login", { username: user.value.username, password: user.value.password }
      ).then(result => {
        console.log(result.data)
        if (result.success) {
          router.replace({ path: '/' })
        }

      })

    };


    return {
      user,
      rules: {
        username: [{ required: true, message: '请输入账号', trigger: 'blur' }],
        password: [{ required: true, message: '请输入密码', trigger: 'blur' }],
      },
      login,
    };
  },
};
</script>
